package main

import (
	"net"
	"log"
	"hq/sock/internal/protocol"
	"os"
	"hq/sock/internal/lg"
)

var (
	slog *log.Logger
)

func main()  {

	l , err := net.Listen("tcp",":7000")
	if err != nil {
		log.Fatal(err)
	}
	defer l.Close()

	slog = log.New(os.Stderr, "demo", log.Ldate|log.Ltime|log.Lmicroseconds)
	protocol.TCPServer(l,DemoHandler{},logf)
}

type DemoHandler  struct {}

func (this DemoHandler) Handle(con net.Conn)  {
	defer con.Close()
	con.Write([]byte("hello"))
}

func logf(level lg.LogLevel, f string, args ...interface{}) {
	lg.Logf(slog, lg.DEBUG , level, f, args...)
}
